package main

import (
	"gormdemo/database"

	"gorm.io/gen"
	"gorm.io/gorm"
)

type Student struct {
	gorm.Model
	Code  string
	Price uint
}

// Dynamic SQL
type Querier interface {
	// SELECT * FROM @@table WHERE name = @name{{if role !=""}} AND role = @role{{end}}
	FilterWithNameAndRole(name, role string) ([]gen.T, error)
}

func main() {
	g := gen.NewGenerator(gen.Config{
		OutPath: "../query",
		Mode:    gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode
	})

	// gormdb, _ := gorm.Open(mysql.Open("root:@(127.0.0.1:3306)/demo?charset=utf8mb4&parseTime=True&loc=Local"))
	//   g.UseDB(gormdb) // reuse your gorm db
	g.UseDB(database.NewDatabase()) // reuse your gorm db

	// // Generate basic type-safe DAO API for struct `model.User` following conventions
	g.ApplyBasic(g.GenerateAllTable()...) // 不太明白

	// // Generate Type Safe API with Dynamic SQL defined on Querier interface for `model.User` and `model.Company`
	// g.ApplyInterface(func(Querier) {}, Student{}, Student{})

	// Generate the code
	g.Execute()
}
